<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  <div class="nav">
    <a href="#home">首页</a>
    <a href="#news">新闻</a>
    <a href="#about">关于</a>
    <a href="#comeon">加入</a>
  </div>
  <div class="cont">

  </div>
</body>
<script>

  // "http://map.baidu.com:80/abc/xyz/index.html?un=admin&pw=123456#3_4"

  // 核心：修改hash

  // console.log( location );

  const cont = document.querySelector(".cont")

  let a = "<h1>这是首页</h1>";
  let b = "<h1>这是新闻列表</h1>";
  let c = "<h1>这是关于我们</h1>";
  let d = "<h1>这是加入我们</h1>";

  render("#home");

  window.onhashchange = function(){
    render(location.hash);
  }

  function render(hash){
    switch(hash){
      case "#home":
        cont.innerHTML = a;break;
      case "#news":
        cont.innerHTML = b;break;
      case "#about":
        cont.innerHTML = c;break;
      case "#comeon":
        cont.innerHTML = d;break;
    }
  }
  
</script>
</html>